package srdb.migration.dbhandler.srdb;


import java.io.FileInputStream;
import java.util.Properties;

import org.postgresql.Driver;

import srdb.migration.common.MTKConnection;

public class SRDBConnection extends MTKConnection {
    private Driver driver = null;


    public SRDBConnection() {
    }

    public SRDBConnection(String dbURL, String dbUser, String dbPassword) throws Exception {
        super(dbURL, dbUser, dbPassword);

        this.driver = new Driver();

        Properties prop = new Properties();
        prop.setProperty("user", dbUser);
        prop.setProperty("password", dbPassword);
        prop.setProperty("loginTimeout", "10");
        prop.setProperty("detmsgencoding", "");
        this.conn = this.driver.connect(dbURL, prop);
    }

    public SRDBConnection(String propertiesFile)
            throws Exception {
        super(propertiesFile);

        Properties ini = new Properties();
        ini.load(new FileInputStream(propertiesFile));

        this.dbURL = ini.getProperty("PostgresConnection");
        this.dbUser = ini.getProperty("PostgresUser");
        this.dbPassword = ini.getProperty("PostgresPassword");
        this.driver = new Driver();

        Properties prop = new Properties();
        prop.setProperty("user", this.dbUser);
        prop.setProperty("password", this.dbPassword);
        prop.setProperty("loginTimeout", "10");
        prop.setProperty("detmsgencoding", "");
        this.conn = this.driver.connect(this.dbURL, prop);
    }



    public boolean preConnectDB(String[] dbInfo) throws Exception {
        boolean connMsg = true;
        // String url = "jdbc:srdbsql://" + dbInfo[0] + ":" + dbInfo[1] + ":" + dbInfo[2];
        String url = "jdbc:postgresql://" + dbInfo[0] + ":" + dbInfo[1] + ":" + dbInfo[2];
        //jdbc:srdbsql://10.168.250.31:1975/srdb

        String user = dbInfo[3];
        String password = dbInfo[4];
        SRDBConnection srdbConnection = new SRDBConnection(url, user, password);

        return connMsg;
    }
}

/* 

 * 
 */